package com.shenmazong.serveruserapi.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SmsUtils {

    /**
     * TODO sendAliyunSms 阿里云发送短信
     * @param mobile
     * @param vcode
     * @return
     */
    public static Integer sendAliyunSms(String mobile, String vcode) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4G4Y2GEG13oXJXdDSNWv", "ShZxvbLVeRrASfpUvWhGSvued0Gl5O");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        //request.putQueryParameter("PhoneNumbers", "18661503812");
        request.putQueryParameter("PhoneNumbers", mobile);
        request.putQueryParameter("SignName", "微赚");
        request.putQueryParameter("TemplateCode", "SMS_200187658");
        //request.putQueryParameter("TemplateParam", "{\"code\": \"111222\"}");
        request.putQueryParameter("TemplateParam", "{\"code\": \"" + vcode +"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
            return 1;
        } catch (ClientException e) {
            e.printStackTrace();
            return 2;
        }

        return 0;
    }

    public static void main(String[] args) {
        SmsUtils.sendAliyunSms("13145218393", "888999");
    }
}
